package cn.sccl.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.sccl.domain.Customer;
import cn.sccl.service.CustomerService;
import cn.sccl.service.impl.CustomerServiceImpl;

/**
 * @author raoshuang
 * @date 2019年8月26日上午9:22:24
 * @version 1.0.0
 *  显示客户信息的Servlet
 */
public class ListCustomerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CustomerService cs = new CustomerServiceImpl();
	
    public ListCustomerServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//1 调用Service查询所有客户
		List<Customer> list = cs.getAll();
		//2 将客户列表放入request域
		request.setAttribute("list", list);
		//3 转发到list.jsp显示
		request.getRequestDispatcher("/jsp/customer/list.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
